<!-- 分配权限 -->
<template>
    <Tree :data="authTree" ref="tree" :check-directly='true'  @on-check-change="getSelectAuth" show-checkbox class="trees"></Tree>
</template>
<script>
// import { getAuth,getRole } from "@/api/staff";
    export default {
        props:{
            authTrees:{
                type:Array,
                default:()=>{return []}
            },
        },
        data () {
            return {
                authTree:[],
                authData: [
                    {
                        title: '总公司',
                        expand: true,
                        checked:true,
                        children: [
                            {
                                title: '分公司1',
                                expand: true,
                                checked:true,
                                children: [
                                    {
                                        title: '子公司1',
                                        checked:true,
                                    },
                                    {
                                        title: '子公司2'
                                    }
                                ]
                            },
                            {
                                title: '分公司2',
                                expand: true,
                                children: [
                                    {
                                        title: '子公司1'
                                    },
                                    {
                                        title: '子公司2'
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        title: '总公司',
                        expand: true,
                        children: [
                            {
                                title: '分公司1',
                            },
                        ]
                    }

                ]
            }
        },
        computed:{
            setAuth(){
                this.authTree = this.authTrees;
                //console.log(this.authTrees);
            }
        },
        methods:{
            getNodes: function () {
                return this.$refs.tree.getCheckedAndIndeterminateNodes();
            },
            getSelectAuth(data){
                this.getNodes()
                var node = this.$refs.tree.getCheckedAndIndeterminateNodes()
                let selectedAuth = [];
                node.forEach(element => {
                    selectedAuth.push(element.code);
                });
                this.$emit("getNewestAuth",selectedAuth);
                
            },
            
        },
        watch:{
            setAuth(a,b){
                //console.log(a);
                //console.log(b);
            }
        },
        mounted(){
            // this.setAuth;
            // console.log(this.authTrees);
        }
    }
</script>
<style lang='less'>
</style>